<template>
  <div class="address">
    <van-nav-bar
      title="我的收货地址"
      left-text="返回"
      right-text="新增地址"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />
    <div class="myAds" v-for="(item, index) in addresslist" :key="index">
      <div class="ads">
        <h3>{{ item.address }}</h3>
        <p>
          <span>{{ item.name }}</span>
          <span>{{ item.phone }}</span>
        </p>
      </div>
      <div class="revise">
        <van-icon name="edit" size="30" class="edit" @click="revise(item)" />
      </div>
    </div>
  </div>
</template>

<script>

import { address_list } from "../../utils/api";
export default {
  data() {
    return {
      addresslist: [],
    };
  },
  methods: {
    onClickLeft() {
      this.$router.push('/buygoods');
    },
    onClickRight() {
      this.$router.push("/addAddress");
    },
    revise(item){
      this.$router.push('/revise/'+JSON.stringify(item));
      console.log(JSON.stringify(item));
    }
  },
  mounted() {
    var userid = JSON.parse( localStorage.getItem('userinfo')).id;
    address_list({userid}).then((res) => {
      // console.log(res.data.list);
      this.addresslist = res.data.list.reverse();
    });
  },
};
</script>

<style lang="scss" scoped>
*{
  margin: 0;
  padding: 0;
}
.myAds {
  display: flex;
  justify-content: space-between;
  // margin: 20px;
  padding: 0 10px;
  background-color: aqua;
  margin: 5px 0;
  border-radius: 10px;
  
  .ads {
    // height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    // height: 50px;
    p {
      color: #999;
      span {
        margin-right: 10px;
      }
    }
  }
  .revise {
    .edit {
      line-height: 50px;
    }
  }
}
</style>